package com.cskaoyan.controller;

import com.cskaoyan.bean.MarketGoods;
import com.cskaoyan.bean.bo.AdminGoodsListBO;
import com.cskaoyan.bean.bo.CreateGoodsBO;
import com.cskaoyan.bean.bo.GoodsDetailBO;
import com.cskaoyan.bean.common.BaseRespVo;
import com.cskaoyan.bean.common.CommonData;
import com.cskaoyan.bean.vo.CatAndBrandVO;
import com.cskaoyan.bean.vo.SimpleRespVO;
import com.cskaoyan.service.AdminGoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author : gao
 * @since: 2022/10/11  20:58
 */
@RestController
@RequestMapping("admin/goods")
public class AdminGoodsController {

    @Autowired
    AdminGoodsService adminGoodsService;

    /**
     * @return {@link null}
     * @author gao
     * @since 2022/10/11 23:05
     */
    @RequestMapping("list")
    public BaseRespVo<CommonData> list(AdminGoodsListBO adminGoodsListBO) {
        BaseRespVo baseRespVo = adminGoodsService.queryGoodsList(adminGoodsListBO);
        return baseRespVo;
    }

    @RequestMapping("catAndBrand")
    public BaseRespVo<CatAndBrandVO> catAndBrand() {
        CatAndBrandVO catAndBrandVO = adminGoodsService.queryCatAndBrandVO();
        return BaseRespVo.ok(catAndBrandVO, "成功");
    }

    @RequestMapping("create")
    public SimpleRespVO createGoods(@RequestBody CreateGoodsBO createGoodsBO) {
        adminGoodsService.createGoods(createGoodsBO);

        return SimpleRespVO.ok(0, "成功");
    }

    @RequestMapping("detail")
    public BaseRespVo<GoodsDetailBO> detail(Integer id) {
        GoodsDetailBO goodsDetailBO = adminGoodsService.detailGoods(id);
        return BaseRespVo.ok(goodsDetailBO,"成功");
    }

    @RequestMapping("delete")
    public SimpleRespVO deleteGoods(@RequestBody MarketGoods marketGoods){
        Integer id = marketGoods.getId();
        adminGoodsService.deleteGoods(id);
        return  SimpleRespVO.ok(0,"成功");
    }

    /**
         * 编辑商品
         * @return {@link null}
         * @author gao
         * @since 2022/10/13 0:47
         */
    @RequestMapping("update")
    public SimpleRespVO updateGoods(@RequestBody CreateGoodsBO createGoodsBO){
        adminGoodsService.updateGoods(createGoodsBO);
        return  SimpleRespVO.ok(0,"成功");
    }



}
